﻿namespace IchiaTester
{
    public static class UartSetting
    {
        public const int UART_TX_FRAME_NUM = 8;
        public const int UART_RX_FRAME_NUM = 8;
        public const int DEFAULT_BUFFER_SIZE = 64;

        public const byte UART_TX_HEADER0 = 0x55;
        public const byte UART_TX_HEADER1 = 0xAA;
        public const byte UART_RX_HEADER0 = 0xAA;
        public const byte UART_RX_HEADER1 = 0x55;
        public const byte UART_TAIL0 = 0xFF;
        public const byte UART_TAIL1 = 0xFF;

        //UART Frame 
        public const int POS_HEADER0 = 0;
        public const int POS_HEADER1 = 1;
        public const int POS_FUNCTION = 2;
        public const int POS_ORDER = 3; //順序(CaseID)
        public const int POS_VALUE0 = 4;
        public const int POS_VALUE1 = 5;
        public const int POS_TAIL0 = 6;
        public const int POS_TAIL1 = 7;
    }

    public static class UartFunction
    {
        //UART Command
        public const byte CMD_START_STOP = 1;
        public const byte CMD_EMERGENCY_STOP = 2;
        public const byte CMD_RESET = 0x03;
        public const byte CMD_SET_POWER = 0x04;
        public const byte CMD_TEST_EXE = 0x10;
    }

    public static class UartValue
    {
        //parameter
        public const byte DONT_CARE = 0;

        public const byte OFF = 0x00;
        public const byte ON = 0x01;

        public const byte PARM_TEST_START = 1;
        public const byte PARM_TEST_END = 2;
        public const byte PARM_RESET_STATUS = 0xAB;
        public const byte PARM_RESET0 = 0xBA;
        public const byte PARM_RESET1 = 0xEE;
    }

    public static class UartParmValue
    {
        //Value
        public const byte VAL_PASS = 1;
        public const byte VAL_FAIL = 2;
    }

    /// <summary>
    /// Modbus设置常量
    /// </summary>
    public static class ModbusSetting
    {
        public const int MODBUS_TX_FRAME_LEN = 8; // Modbus发送帧长度

        public const int MODBUS_RX_FRAME_LEN = 7; // Modbus返回帧长度
        //public static int MODBUS_BUFFER_SIZE = 64;

        public static byte MODBUS_SLAVE_ADDRESS;

        public static ushort MODBUS_REGISTER;

        //public static byte MODBUS_REGISTER0;
        //public static byte MODBUS_REGISTER1;
        public static ushort MODBUS_NUM_OF_REG;
        //public static byte MODBUS_NUM_OF_REG0;
        //public static byte MODBUS_NUM_OF_REG1;

        //Modbus Tx Frame Modbus协议发送报文帧
        public const int POS_SLAVE_ADDRESS = 0; // 从站地址
        public const int POS_FUNCTION = 1; // 功能码
        public const int POS_REGISTER0 = 2; // 起始地址0
        public const int POS_REGISTER1 = 3; // 其实地址1
        public const int POS_NUM_OF_REG0 = 4; // 长度0
        public const int POS_NUM_OF_REG1 = 5; // 长度1
        public const int POS_CRC0 = 6; // CRC校验0
        public const int POS_CRC1 = 7; // CRC校验1

        //Modbus Rx Frame Modbus协议接收报文帧
        public const int POS_NUM_OF_DATA = 2;
        public const int POS_RX_VALUE0 = 3;
        public const int POS_RX_VALUE1 = 4;
        public static int NUM_OF_DATA;
        public const int POS_OF_RX_CRC1 = 5;
        public const int POS_OF_RX_CRC2 = 6;
    }

    public static class ModbusFunction
    {
        //UART Command
        public const byte CMD_READ_MULTI_REGISTER = 0x03;
        public const byte CMD_WRITE_SINGLE_REGISTER = 0x06;
        public const byte CMD_WRITE_MULTI_REGISTER = 0x10;
    }

    public static class CustomSetting
    {
        public static int CUSTOM_FRAME_NUM;
        public const int CUSTOM_BUFFER_SIZE = 64;
    }
}